﻿@model QLMB.ViewModels.InfoFlight
@using QLMB.Infrastructure           

@{
    ViewBag.Title = "ListFight";
    ViewBag.sl = Model.SoNguoiLon + Model.SoTreEm;
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
@section script {
    <script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.js" type="text/javascript"></script>
}

<script language = "javascript" type ="text/javascript">
    function formatDollar(num) {
        var p = num.toFixed(2).split(".");
        return p[0].split("").reverse().reduce(function (acc, num, i, orig) {
            return num + (i && !(i % 3) ? "," : "") + acc;
        }, "") + "." + p[1];
    }
    $(document).ready(function () {
        var MaCBdi = $("input[name='MaChuyenBayDi']:checked").val();
        var sl = $("#tongsonguoi").val();
        if (MaCBdi != null) {
            $.getJSON("/Book/GetListServices/", { id: MaCBdi, sldv: sl },
                function (json) {
                    $("input[name='Loaidichvudi']:checked").attr('checked', false);
                    $(".infoservice > div").hide();
                    $.each(json, function (index, itemData) {
                        var temp = "" + itemData.Value;
                        $("." + temp).show();
                    });

                });
        }

        var MaCBve = $("input[name='MaChuyenBayVe']:checked").val();
        var sl = $("#tongsonguoi").val();
        if (MaCBve != null) {
            $.getJSON("/Book/GetListServices/", { id: MaCBve, sldv: sl },
                function (json) {
                    $("input[name='Loaidichvuve']:checked").attr('checked', false);
                    $(".infoservice > div").hide();
                    $.each(json, function (index, itemData) {
                        var temp = "" + itemData.Value;
                        $("." + temp).show();
                    });
                });
        }

        $('input[name="Loaidichvudi"]:radio').click(function () {
            var madv = "LDV" + $(this).val();
            var giadv = $("#" + madv).val();
            var macb = $("input[name='MaChuyenBayDi']:checked").val();
            var giave = $("#GiaCB" + macb).val();
            var giatien = (eval(giave) + eval(giadv) + eval(giave) / 100 * 5);
            $("#" + macb).text(formatDollar(giatien));
        });

        $('input[name="Loaidichvuve"]:radio').click(function () {
            var madv = "LDV" + $(this).val();
            var giadv = $("#" + madv).val();
            var macb = $("input[name='MaChuyenBayVe']:checked").val();
            var giave = $("#GiaCB" + macb).val();
            var giatien = (eval(giave) + eval(giadv) + eval(giave) / 100 * 5);
            $("#" + macb).text(formatDollar(giatien));
        });

        $("input[name='MaChuyenBayDi']").click(function () {
            $(".GVCB").each(function () {
                var temp = $(this).attr("id");
                var giacb = $("#GiaCB" + temp).val();
                $(this).text(formatDollar(eval(giacb)));
            });
            var MaCBdi = $(this).val();
            var sl = $("#tongsonguoi").val();
            $.getJSON("/Book/GetListServices/", { id: MaCBdi, sldv: sl },
                function (json) {
                    $("input[name='Loaidichvudi']:checked").attr('checked', false);
                    $(".infoservice > div").hide();
                    $.each(json, function (index, itemData) {
                        var temp = "" + itemData.Value;
                        $("." + temp).show();
                    });
                });
        });

        $("input[name='MaChuyenBayVe']").click(function () {
            $(".GVCB").each(function () {
                var temp = $(this).attr("id");
                var giacb = $("#GiaCB" + temp).val();
                $(this).text(formatDollar(eval(giacb)));
            });
            var MaCBdi = $(this).val();
            var sl = $("#tongsonguoi").val();
            $.getJSON("/Book/GetListServices/", { id: MaCBdi, sldv: sl },
                function (json) {
                    $("input[name='Loaidichvuve']:checked").attr('checked', false);
                    $(".infoservice > div").hide();
                    $.each(json, function (index, itemData) {
                        var temp = "" + itemData.Value;
                        $("." + temp).show();
                    });
                });
        });
    });
</script>

<h2>ĐẶT VÉ CHUYẾN BAY - @ViewBag.TUADE</h2>
<center>
<table border = "1px">
    <tr>
    @for (int i = -3; i < 4; i++)
    {
        <td>    
            @{string day = string.Format("{0:ddd dd MMM}", ViewBag.NGAYDI.AddDays(i));}
            @if (ViewBag.TIME == 0)
            {
                @Html.ActionLink(day, "ListFight",
                new
                {
                    Sanbaydi = Model.Sanbaydi,
                    Sanbayden = Model.Sanbayden,
                    Ngaydi = Model.Ngaydi.AddDays(i),
                    Ngayve = Model.Ngayve,
                    Loaive = Model.Loaive,
                    SoNguoiLon = Model.SoNguoiLon,
                    SoTreEm = Model.SoTreEm,
                    time = ViewBag.TIME,
                    LoaiDVdi = Model.Loaidichvudi,
                    LoaiDVden = Model.Loaidichvuve,
                    MaCBdi = Model.MaChuyenBayDi,
                    MaCBden = Model.MaChuyenBayVe

                })
            }
            else
            {
                @Html.ActionLink(day, "ListFight",
                new
                {
                    Sanbaydi = Model.Sanbaydi,
                    Sanbayden = Model.Sanbayden,
                    Ngaydi = Model.Ngaydi,
                    Ngayve = Model.Ngayve.AddDays(i),
                    Loaive = Model.Loaive,
                    SoNguoiLon = Model.SoNguoiLon,
                    SoTreEm = Model.SoTreEm,
                    time = ViewBag.TIME,
                    LoaiDVdi = Model.Loaidichvudi,
                    LoaiDVden = Model.Loaidichvuve,
                    MaCBdi = Model.MaChuyenBayDi,
                    MaCBden = Model.MaChuyenBayVe

                })
            }
            
            <br />
            @if (ViewBag.GiaTuan[ViewBag.NGAYDI.AddDays(i)] == -1)
            {
                @Html.Label("No Flight!")
            }
            else
            {
                string giatien = string.Format("{0:0,0}", ViewBag.GiaTuan[ViewBag.NGAYDI.AddDays(i)]);
                @Html.Label(giatien)
            }
        </td>
    }
    </tr>
</table>
</center>
<br />
@using (Html.BeginForm())
{
    
    if (ViewBag.DSCB != null)
    {
        <fieldset>
        <legend>DANH SACH CAC CHUYEN BAY NGAY @string.Format("{0:dd/MM/yyyy}", ViewBag.NGAYDI)</legend>
        <table>
            <tr>
                <th>Khởi hành</th>
                <th>Đến</th>
                <th>Chuyến bay</th>
                <th>Giá vé</th>
            </tr>
            @foreach (QLMB.Models.CHUYENBAY item in ViewBag.DSCB)
            {
            <tr>
                <td>
                    @string.Format("{0:HH:mm}", item.NgayDi)
                    <br />
                    @Html.Label((string)item.DUONGBAY.SANBAY.THANHPHO.TenTP)
                </td>
                <td>
                    @string.Format("{0:HH:mm}", item.NgayDen)
                    <br />
                    @Html.Label((string)item.DUONGBAY.SANBAY1.THANHPHO.TenTP)
                </td> 
                <td>
                    @Html.Label((string)item.DUONGBAY.HanhTrinh)
                </td>
                <td>
                    @if (ViewBag.TIME == 0)
                    {
                        @Html.CheckedRadioButtonFor(x => x.MaChuyenBayDi, item.MaCB)
                    }
                    else
                    {
                        @Html.CheckedRadioButtonFor(x => x.MaChuyenBayVe, item.MaCB)
                    }
                    <label id="@item.MaCB" class="GVCB">@string.Format("{0:0,0}", (item.DUONGBAY.GiaCoBan - item.DUONGBAY.GiaCoBan * item.KhuyenMai / 100))</label>
                    @Html.Hidden("GiaCB" + item.MaCB, Decimal.ToInt64((Decimal)(item.DUONGBAY.GiaCoBan - item.DUONGBAY.GiaCoBan * item.KhuyenMai / 100)))
                </td>
            </tr>
            }
        </table>
        </fieldset>        
        <fieldset>
        <legend>CAC GOI DICH VU CUA HANG</legend>
        <p style = "font-style:italic;">Số lượng chỗ quý khách yêu cầu là: @ViewBag.sl</p>    
        <table>
            @if (ViewBag.TIME == 0)
            {
                <tr>
                @foreach (QLMB.Models.LOAIDICHVU item in ViewBag.DSDV)
                {
                    <td class = "infoservice">
                    <div class = "@item.MaLoaiDV">
                        @Html.CheckedRadioButtonFor(x => x.Loaidichvudi, item.MaLoaiDV)
                        @item.TenDichVu
                        @Html.Hidden("GiaTien",Decimal.ToInt64((Decimal)item.TongTien),new{id = "LDV"+item.MaLoaiDV.Trim()})
                        <br />
                        <hr />
                        <div>
                        <h4>Thong tin dich vu</h4>
                        <span>@item.MoTa</span>
                        <h4>Cac dich vu di kem</h4>
                        @foreach (QLMB.Models.DICHVU dv in item.DICHVUs.AsEnumerable())
                        {
                            <span>@dv.TenDichVu</span>
                            <span>@dv.MoTa</span>
                            <br />
                        }
                        </div>
                    </div>
                    </td>
                }
                </tr>
            }
            else
            {
                <tr>
                @foreach (QLMB.Models.LOAIDICHVU item in ViewBag.DSDV)
                {
                    <td class = "infoservice">
                    <div class = "@item.MaLoaiDV">
                        @Html.CheckedRadioButtonFor(x => x.Loaidichvuve, item.MaLoaiDV, false)
                        @item.TenDichVu
                        @Html.Hidden("GiaTien",Decimal.ToInt64((Decimal)item.TongTien),new{id = "LDV"+item.MaLoaiDV.Trim()})
                        <br />
                        <hr />
                        <div class = "infoservice">
                        <h4>Thong tin dich vu</h4>
                        <span>@item.MoTa</span>
                        <h4>Cac dich vu di kem</h4>
                        @foreach (QLMB.Models.DICHVU dv in item.DICHVUs.AsEnumerable())
                        {
                            <span>@dv.TenDichVu</span>
                            <span>@dv.MoTa</span>
                            <br />
                        }
                        </div>
                    </div>
                    </td>
                }
                </tr>
            }
        </table>
        </fieldset>
        <br />
        @Html.ValidationMessageFor(x => x.Loaidichvudi);
        @Html.ValidationMessageFor(x => x.Loaidichvuve);
        <br />                                               
        <input type="submit" value="Tiep tuc" />

    }
    else
    {
        @Html.Label("Khong co chuyen bay nao trong ngay nay")
        <br />
        <input type="submit" value="Chon ngay khac" />
        
    }
    @Html.Hidden("tongsonguoi", @Model.SoNguoiLon + @Model.SoTreEm)
}


